package com.zenith.edu.controller;

import com.zenith.common.annotation.request.SecurePostMapping;
import com.zenith.common.result.Result;
import com.zenith.edu.po.dto.EduCheckinDTO;
import com.zenith.edu.po.vo.EduCheckinVO;
import com.zenith.edu.service.EduCheckinService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/edu/checkin")
@Tag(name = "签到管理", description = "签到管理接口")
public class EduCheckinController {
    
    @Autowired
    private EduCheckinService eduCheckinService;
    
    @SecurePostMapping(value = "/createCheckin",roles = {"ADMIN"},permission = "checkin:create")
    @Operation(summary = "创建签到")
    public Result<EduCheckinVO> createCheckin(@RequestBody EduCheckinDTO dto) {
        EduCheckinVO checkinVO = eduCheckinService.createCheckin(dto);
        return Result.success(checkinVO);
    }
    
    @SecurePostMapping(value = "/getCheckinById/{id}",roles = {"ADMIN"},permission = "checkin:read")
    @Operation(summary = "根据ID获取签到详情")
    public Result<EduCheckinVO> getCheckinById(@PathVariable Long id) {
        EduCheckinVO checkinVO = eduCheckinService.getCheckinById(id);
        if (checkinVO == null) {
            return Result.fail("签到不存在");
        }
        return Result.success(checkinVO);
    }
    
    @SecurePostMapping(value = "/updateCheckin",roles = {"ADMIN"},permission = "checkin:update")
    @Operation(summary = "更新签到信息")
    public Result<EduCheckinVO> updateCheckin(@RequestBody EduCheckinDTO dto) {
        EduCheckinVO checkinVO = eduCheckinService.updateCheckin(dto);
        return Result.success(checkinVO);
    }
    
    @SecurePostMapping(value = "/deleteCheckin/{id}",roles = {"ADMIN"},permission = "checkin:delete")
    @Operation(summary = "删除指定签到")
    public Result<Void> deleteCheckin(@PathVariable Long id) {
        boolean result = eduCheckinService.deleteCheckin(id);
        if (!result) {
            return Result.fail("签到删除失败");
        }
        return Result.success();
    }
    
    @SecurePostMapping(value = "/getCheckinList",roles = {"ADMIN"},permission = "checkin:read")
    @Operation(summary = "获取签到列表")
    public Result<List<EduCheckinVO>> getCheckinList() {
        List<EduCheckinVO> checkinList = eduCheckinService.getCheckinList();
        return Result.success(checkinList);
    }
}